<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<title>yukari world</title>
<#include "/lib/base_source.ftl">
<style type="text/css">
</style>
</head>
<body>
<div class='whole-container'>
<#include "/lib/header.ftl">
    <div>
        <ul class="breadcrumb">
        	<li>签到管理</li><span class="divider">/</span>
            <li>${user.name}出勤</li>
        </ul>
    </div>
    <div class="container-fluid">
        <div class="row-fluid">
            <div class="container span12">
            <#include "/lib/alert.ftl">

                <div class='main-content'>
                    <div class="table-content">
                    <#-- table -->
                        <table class="table table-striped table-bordered table-condensed" id="itemTable" style="font-size:12px;word-break:break-all;word-wrap:break-word;">
                            <thead>
                            <tr>
                                <th style="width:44px;"></th>
                                <th style="width:150px;">名字</th>
                                <th style="width:75px;"><span>赐名</span><span class="glyphicon glyphicon-chevron-left" style="float:right;" onclick="showLeftTd()"></span></th>
                                <#list registerList as register>
                                	<th style="text-align:center;display:none;" class="register" data_index="${register_index}">${register.startTime?string('yyyy-MM-dd')}</th>
                                </#list>
                                <th style="width:250px;text-align:center;"><span class="glyphicon glyphicon-chevron-right" style="float:left;" onclick="showRightTd()"></span><span>操作</span></th>
                            </tr>
                            </thead>
                            <tbody>
                            <#if userList??>
                            <#list userList as item>
                            	<tr id="user${item.id}" >
                            		<td name="redBanner" style="font-size:22px"><#if item.redBanner == 1><img src="${rc.contextPath}/images/hongqi_64.png" style="width:32px" /></#if></td>
                                	<td style="line-height:34px;">${item.name!}</td>
                                	<td style="line-height:34px;">${item.nick!}</td>
                                	<#list item.statusList as status>
                                	<td style="text-align:center;line-height:34px;display:none;" class="register" data_index="${status_index}">
                                	<#if status == 0>
                                	<img src="${rc.contextPath}/images/qiandao_64.png" style="width:32px"/>
                                	<#elseif status == 1>
                                	<img src="${rc.contextPath}/images/chidao_32.png" style="width:16px" />
                                	</#if>
                                	</td>
                                	</#list>
                                	<td style="line-height:34px;">
                                	<a class="btn btn-info btn-xs" href="javascript:banfa('${item.id}','${(item.redBanner == 1)?string("0","1")}');">${(item.redBanner == 1)?string("收回","颁发")}流动红旗</a>
                                	<a class="btn btn-info btn-xs" href="javascript:chuqin('${item.id}');">查看详细出勤</a>
                                	<a class="btn btn-danger btn-xs" href="javascript:kaichu('${item.id}');">开除学籍</a>
                                	</td>
                                </tr>
                            </#list>
                            </#if>
                            </tbody>
                        </table>
                        <div class="pagination" id="itemPage"></div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    $(document).ready(function(){
    	showTd(maxTd-7);
    });
	    
	function startRegister(){
		location.href = "${rc.contextPath}/admin/register/startRegister";
	}
	function stopRegister(){
		location.href = "${rc.contextPath}/admin/register/stopRegister";
	}
	
	
	function banfa(id,status) {
		$.ajax({
			url : "${rc.contextPath}/admin/register/redBanner",
	    	dataType : "json",
	    	data :  {'status':status,'id':id},
	    	type:'post',
	    	success:function(json){
	    		var tds = $("#user"+id).find("td");
	    		var a = tds.last().find("a").first();
	    		if (status == 1){
		    		tds.first().html('<img src="${rc.contextPath}/images/hongqi_64.png" style="width:32px" />');
		    		a.attr("href","javascript:banfa('"+id+"','0')");
		    		a.html("收回流动红旗")
	    		} else {
	    			tds.first().html('');
		    		a.attr("href","javascript:banfa('"+id+"','1')");
		    		a.html("颁发流动红旗")
	    		}
	    	}
		});
	}
	
	function kaichu(id){
		if (confirm('是否确定？')){
			var a = $("<form method='post' action='${rc.contextPath}/admin/register/deleteUser' ></form>")
			a.append("<input type='text' name='userId' value='"+id+"'/>")
			a.submit();
		}
	}
	var maxTd=${registerSize};
	function showLeftTd(){
		var tds = $(".register:visible");
		var index = $(tds[0]).attr("data_index");
		showTd(index-1);
	}
	function showRightTd(){
		var tds = $(".register:visible");
		var index = $(tds[tds.length-1]).attr("data_index");
		showTd(index-5);
	}
	function showTd(ii){
		if (ii+7 > maxTd) {
			return;
		} else if(ii < 0) {
			return;
		}
		$(".register:visible").hide();
		for(var i=ii;i<ii+7;i++){
			$(".register[data_index="+i+"]").show();
		}
		
	}

</script>
</body>
</html>